package cn.zwx.common.sentinel.handler;

import cn.zwx.base.entity.ResponseEntity;
import cn.zwx.base.enums.ResponseCodeEnum;
import cn.zwx.common.sentinel.properties.ZwxSentinePropreties;
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException;
import com.alibaba.csp.sentinel.slots.system.SystemBlockException;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author zhangwenxue
 */
@Component
public class CustomerBlockHandler implements BlockExceptionHandler{
    @Resource
    private ZwxSentinePropreties propreties;
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, BlockException e) throws Exception {
        cn.zwx.common.sentinel.handler.BlockExceptionHandler handler = new cn.zwx.common.sentinel.handler.BlockExceptionHandler(propreties);
        handler.processBlockException(httpServletRequest, httpServletResponse, e);
    }


    @PostConstruct
    public void init() {
        new CustomerBlockHandler();
    }

    @Data
    static class SentinelErrorMsg {
        private Integer status;
        private String msg;
    }
}
